<template>
    <div>
        <h1>添加</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>会员卡号</td>
                    <td><input type="text" v-model="info.memberCode"></td>
                </tr>
                 <tr>
                    <td>会员手机号</td>
                    <td><input type="text" v-model="info.tel"></td>
                </tr>
                 <tr>
                    <td>会员名称</td>
                    <td><input type="text" v-model="info.userName"></td>
                </tr>
                <tr>
                    <td>证件类型</td>
                    <td><select v-model="info.cardType">
                        <option value="">请选择</option>
                        <option :value="item" v-for="item in arr">{{item}}</option>
                    </select></td>
                </tr>
                 <tr>
                    <td>证件号码</td>
                    <td><input type="text" v-model="info.card"></td>
                </tr>
                 <tr>
                    <td>会员级别</td>
                    <td><select v-model="info.leaveId">
                        <option value="">请选择</option>
                        <option :value="item.memberId" v-for="item in getselect">{{item.memberName}}</option>
                    </select></td>
                </tr>
                 <tr>
                    <td>会员生日</td>
                    <td><input type="date" v-model="info.birthday"></td>
                </tr>
                 <tr>
                    <td>会员性别</td>
                    <td><input type="radio" name="sex" v-model="info.gender" :value="1">男
                    <input type="radio" name="sex" v-model="info.gender" :value="0" >女</td>
                </tr>
                <tr>
                    <td>会员积分</td>
                    <td><input type="text" v-model="info.score"></td>
                </tr>
                 <tr>
                    <td>会员余额</td>
                    <td><input type="text" v-model="info.money"></td>
                </tr>
             
                 <tr>
                    <td>会员爱好</td>
                    <td>
                        <input type="checkbox" name="likes" value="吃" v-model="info.likes">吃
                        <input type="checkbox" name="likes" value="喝" v-model="info.likes">喝
                        <input type="checkbox" name="likes" value="玩" v-model="info.likes">玩
                        <input type="checkbox" name="likes" value="乐" v-model="info.likes">乐
                </td>
                </tr>
                 <tr>
                    <td>会员简介</td>
                    <td><textarea rows="5" cols="50"  v-model="info.desc" >

                    </textarea></td>
                </tr>
                <tr>
                    <td>是否选中条款</td>
                    <td><input type="checkbox"  v-model="info.isAgree">XXX条款</td>
                </tr>
                 <tr>
                    <td></td>
                    <td><input type="button" class="btn btn-primary" value="提交" @click="add" ></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue';
import axios from 'axios'
import moment from 'moment'
import {useRouther,useRout} from "vue-router";
let info:any=reactive({
    
  "memberCode": moment(new Date()).format('YYYYMMDD')+Math.random().toString().substring(2,5),
  "tel": "",
  "userName": "",
  "card": "",
  "birthday": "",
  "score": "",
  "money": "",
  "leaveId": "",
  "gender": 1,
  "likes": [],
  "desc": "",
  "isAgree": "",
  "cardType": "",
  

 
})
onMounted(()=>
{
    getlist();
})
let arr:any=ref(['身份证','驾驶证','港澳通行证']);
let getselect:any=ref([])
const getlist=()=>
{
    axios({
        url:"http://localhost:5237/api/Member/GetMemberList",
        method:"get",
        
    })
    .then((res)=>
    {
        console.log(res);
        getselect.value=res.data;
    })
    .catch((err)=>
    {
        console.log(err);
    })
}
const add=()=>
{
    info.likes=info.likes.toString()
    axios({
        url:"http://localhost:5237/api/Member/AddMerber",
        method:"post",
        data:info
    })
    .then((res)=>
    {
        console.log(res);
        if(res.data==-1)
        {
            alert("用户名不唯一");
            return;
        }
        if(res.data>0)
        {
            alert("添加成功");
            router.push("/memberShow");
            return;
        }
        else
        {
            alert("添加失败");
            return;
        }
    })
    .catch((err)=>
    {
        console.log(err);
    })
}
</script>

<style scoped>

</style>